package cn.gjxblog.modules.sys.controller;

import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.modules.sys.entity.SysMenuEntity;
import cn.gjxblog.modules.sys.model.vo.MenuListRequest;
import cn.gjxblog.modules.sys.service.SysMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * 菜单管理
 *
 * @author guojiaxun
 * @date 2019-09-17 11:32:47
 */
@RestController
@RequestMapping("sys/sysmenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/listMenuTree")
    @ApiOperation("获取菜单")
    public HttpResult<List<SysMenuEntity>> getPermissionMenu(String uid){
        List<SysMenuEntity> data = sysMenuService.getPermissionMenu(uid);
        return HttpResult.ok(data);
    }



    /**
     * 列表
     */
    @PostMapping("/listMenu")
    @ApiOperation("获取列表")
    public HttpResult<List<SysMenuEntity>> listMenu(@RequestBody MenuListRequest requeset){
        List<SysMenuEntity>  data=  sysMenuService.listMenu(requeset);
        return HttpResult.ok(data);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{menuId}")
    @ApiOperation("获取信息")
    public HttpResult info(@PathVariable("menuId") Long menuId){
		SysMenuEntity sysMenu = sysMenuService.getById(menuId);

        return HttpResult.ok(sysMenu);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存信息")
    public HttpResult save(@RequestBody SysMenuEntity sysMenu){
		sysMenuService.save(sysMenu);

        return HttpResult.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改信息")
    public HttpResult update(@RequestBody SysMenuEntity sysMenu){
		sysMenuService.updateById(sysMenu);

        return HttpResult.ok();
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    @ApiOperation("删除信息")
    public HttpResult delete(@RequestBody Long[] menuIds){
		sysMenuService.removeByIds(Arrays.asList(menuIds));
        return HttpResult.ok();
    }

}
